; DESCRIPTION:
; Vertex shader used to render A3DMorphRigidMesh. This shader contains completed
; transfrom and lighting process.
; This shader handle 3 morph channels

; CREATED BY: duyuxin, 2003/10/28
; Copyright (c) 2003 Archosaur Studio, All Rights Reserved.

vs.1.1

;------------------------------------------------------------------------------
; v0 	  = position
; v1 	  = normal
; v2 	  = texture coordinates
; v3-v4   = morph channel 0 position delta and normal delta
; v5-v6   = morph channel 1 position delta and normal delta
; v7-v8   = morph channel 2 position delta and normal delta
;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
; Constants specified by the app;
;
; c11     = world matrix (from model space to world space)
; c10     = palette of morph channel weight (4 weights)
; c9	  = material.specular * light.specular
; c8	  = material.diffuse * light.diffuse
; c7	  = ambient color + emmisive color
; c6	  = eye's direction in world space
; c2-c5   = view matrix * projection matrix (from world space to cuboid space)
; c1	  = light direction in world space
; c0	  = {1, power, 0, 765.01};
;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
; oPos	  = Output position
; oD0	  = Diffuse
; oD1	  = Specular
; oT0	  = texture coordinates
;------------------------------------------------------------------------------

; ============ Morph vertex ================

; Calculate morph position and normal

mov r7, v0	; position in r7
mov r8, v1	; normal in r8

mad r7, c10.xxxx, v3, r7
mad r8, c10.xxxx, v4, r8

mad r7, c10.yyyy, v5, r7
mad r8, c10.yyyy, v6, r8

mad r7, c10.zzzz, v7, r7
mad r8, c10.zzzz, v8, r8

mov r7.w, c0.x	; set w to 1

; normalize normal
dp3 r8.w, r8, r8
rsq r8.w, r8.w
mul r8, r8, r8.w

; ============ Transform position and normal from model space to world space ==========

m4x3 r4, r7, c11
m3x3 r5, r8, c11

; Transfrom position from world space to cuboid space and output it
mov r4.w, c0.x
m4x4 oPos, r4, c2

; ============ Calculate diffuse ============

; Do we need to re-normalize normal ? We just did a rotation, so...
; dp3 r5.w, r5, r5
; rsq r5.w, r5.w
; mul r5, r5, r5.w

dp3 r1.x, r5, -c1     	; normal dot light (N * L)
mul r0, r1.x, c8      	; Multiply with diffuse
add r0, r0, c7        	; Add in ambient
min oD0, r0, c0.x     	; output diffuse, clamp if > 1
mov oD1, c0.zzzx 	  	; output specular as 0

; Copy texture coordinate
mov oT0, v2

